package sealedGenerator;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class KeyFileReader {
	//generic comment to force update
	File keyFile;
	List<String> names;
	public KeyFileReader() throws FileNotFoundException{
		names=new ArrayList<String>();
		keyFile=new File("patches" + File.separator + "key_file.txt");
		Scanner scan=new Scanner(keyFile);
		scan.useDelimiter("%");
		while(scan.hasNextLine()){
			names.add(scan.next());
			scan.nextLine();
		}
	}
	public List<String> getNames(){
		return names;
	}
	public String[] getSetInfo(String setName) throws FileNotFoundException{
		Scanner scan = new Scanner(keyFile);
		scan.useDelimiter("%");
		String[] parts=new String[0];
		while (scan.hasNextLine()){
			if(scan.hasNext(setName)){
				parts = scan.nextLine().split("%");
				break;
			}else{
				scan.nextLine();
			}
		}
		if(parts.length==0){
			throw new FileNotFoundException("Set not in the key file");
		}else{
			return parts;
		}
	}
}
